package com.isunland.managesystem.ui;

import android.os.Bundle;
import com.google.gson.Gson;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.RequisitionDetail;
import com.isunland.managesystem.entity.RequisitionTripOriginal;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * 可用调休关联差旅单dialog
 * Created by lenovo on 2016/4/8.
 */
public class ChooseTripDialogFragment extends BaseNetworkDialogFragment {
  private CurrentUser mUser;

  @Override public void onCreate(Bundle savedInstanceState) {
    mUser = CurrentUser.newInstance(getActivity());
    super.onCreate(savedInstanceState);
  }

  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<CustomerDialog>();
    RequisitionTripOriginal original = new Gson().fromJson(arg0, RequisitionTripOriginal.class);
    ArrayList<RequisitionDetail> dataList = (ArrayList<RequisitionDetail>) original.getRows();
    if (dataList == null || dataList.size() == 0) {

      return null;
    }
    for (int i = 0; i < dataList.size(); i++) {
      list.add(new CustomerDialog(dataList.get(i).getBtripReason(), dataList.get(i).getId()));
    }
    return list;
  }

  @Override public String getUrl() {
    return ApiConst.ULR_TRIP_LIST;
  }

  @Override public HashMap<String, String> getparameters() {
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("regStaffId", mUser.getJobNumber());
    params.put("memberCode", mUser.getMemberCode());
    params.put("dataStatus", "checkPass");
    params.put("orderField", "REG_DATE");
    params.put("orderSeq", "desc");
    params.put("page", "1");
    params.put("rows", "1000");
    return params;
  }
}
